<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<%@include file="/WEB-INF/jsp/base/head.jsp"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> 
<link href="<%=request.getContextPath()%>/css/lightBox.css" rel="stylesheet" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色列表</title>
</head>
<body>
	<div class="center_main">
		<div id="btn-option">
			<d:auth name="admin">
				<a class="add-btn"  id="popAdd"  href="javascript:void(0);" title="新增">新增</a>
				<a class="edit-btn" id="popEdit" href="javascript:void(0);" title="修改">修改</a>
				<a class="del-btn"  id="delete"     href="javascript:void(0)" title="删除">删除</a>
				<a class="enable-btn"  id="enabled"     href="javascript:void(0);" title="启用">启用</a>
				<a class="disable-btn"  id="disabled"     href="javascript:void(0);" title="停用">停用</a>
				<a class="children-btn"  id="roleAuth"   href="javascript:void(0);" title="角色权限">角色权限</a>
				<a class="children-btn"  id="roleResourse"   href="javascript:void(0);" title="角色菜单">角色菜单</a>
				<a class="children-btn" style="margin-left: 15px;"  id="roleUser"   href="javascript:void(0);" title="角色用户">角色用户</a>
			</d:auth>
		</div>
		<div class="center_left"></div>
	</div>

	<div id="page-top">
		<span>角色管理列表</span>
		<b></b><i></i>
	</div>
  
	<div id="page"> 
       
       <s:form id="form1" namespace="/system" action="roleAction!getRoleList" name="form1" method="post">
       		<input type="hidden" name="roleId" id="roleid" />
       		<input type="hidden" id="delURL" value="roleAction!roleDelete.do"/>
       		<input type="hidden" id="enabledURL" value="system/roleAction!enabled.do" />
       		<input type="hidden" id="disabledURL" value="system/roleAction!disabled.do" />
       		<input type="hidden" id="returnURL" value="system/roleAction!getRoleList.do" />

            <div id="search">
       
	       		<div class="search-edit-wapper">
					<label for="">角色名称：</label>
				    <input type="text"  class="form-text" name="roleBizBean.roleName" value="<s:property value='roleBizBean.roleName'/>" />
				</div>
				
			</div>
			
			<div id="search-btn-wapper">
				<s:submit cssClass="btn"  method="getRoleList" value="查询"></s:submit>
			</div>
            
            <div id="item-list">
				<table>
				   <thead>
				     <tr>
						<th>选择<input type="checkbox" id="selectAll" /></th>
						<th>序号</th>
						<th>角色名称</th>
						<th>状态</th>
						<th>角色描述</th>
					 </tr>
				   </thead>
				   <tbody>
						<s:iterator value="roleBizBeanList" var="r" status="sta" > 
						<tr>
							<td><input type="checkbox" class="classCheckbox" name="roleBizBeanList[<s:property value="#sta.index"/>].id" value="<s:property value="id"/>" /></td>
							<td><s:property value="#sta.index+1"/></td>
							<td><s:property value="roleName"/></td>
							<td>
								<d:codeItem name="role_status" value="${markDelete}"></d:codeItem>
								<input type="hidden" id='delete_<s:property value="id"/>' value="<s:property value='markDelete'/>" />
							</td>
							<td><s:property value="description"/></td>
						</tr>
						</s:iterator>
						<s:if test="roleBizBeanList.size == 0">
						    <tr>
						       <td colspan="5">数据暂无!</td>
						    </tr>
						</s:if>
					</tbody>
				</table>
			</div>
       </s:form>
    </div>
    <div id="page-bottom">
	<b></b><i></i>
		<d:page namespace="/system" action="roleAction!getRoleList">
		</d:page>
	</div>
</body>
<script src="<%=request.getContextPath()%>/js/lightBox.js" type='text/javascript'></script>
<script type="text/javascript">
$(function(){
	$("#popAdd").click(function(){
		var body = '<form action="roleAction!save.do" id="roleform" name="roleform" method="post">' +
		'<div class="row"><b class="label">角色名称:</b><input name="roleName" id="roleName" class="input" />&nbsp;&nbsp;<font color="red" id="message">*</font></div>' +		
		'<div class="row"><b class="label">角色状态:</b>'+
		'<select name="status" id="status" style="margin-top: 5px;">' +
		'<option value="N" />正常</option>'+
		'<option value="Y" />停用</option>'+
		'</select><font color="red">&nbsp;&nbsp;*</font>' +
		'</div>' +
		'<div class="row"><b class="label">备注:</b><textarea name="roleRemark" id="roleRemark" rows="3" class="input" style="textmode:multiline;" onkeydown="if (this.value.length>=200){event.returnValue=false}"></textarea></div>' +
		'</form>';
	var	footer='<div style="text-align:center"><input type="button" value="保存" class="divbtn" id="savaBtn"/><input type="button" value="取消" class="divbtn" id="rolecancel" /></div>';
	Box("role",400,200,body,"新建角色",footer);
	});

	$("#savaBtn").live("click", function(){
		if("" == $("#roleName").val()){
			$("#message").html("角色名称不能为空！");
			return false;
		} else {
			$("#message").html("*");
		}
		$.ajax({
			   type: "POST",
			   url: "<%=request.getContextPath()%>/system/roleAction!save.do",
			   data:{'roleBizBean.roleName':$("#roleName").val(),
				     'roleBizBean.description':$("#roleRemark").val(),
				     'roleBizBean.markDelete':$("#status").val()
				    },
			   dataType: "json",
			   async: false,
			   success: function(msg){
						if(msg.msg !=''){
							$("#message").html(msg.msg);
						} else {
							alert("新增角色成功！");
							$("#form1").attr("action", $("#returnURL").val());
							$("#form1").submit();   
						}
			   }
			});
	});
	
	$("#popEdit").click(function(){
		
		var obj = $("input[type=checkbox]:checked.classCheckbox");
		var item = obj.length;
		if(item != undefined &&  item > 0 && item == 1) {
			$.ajax({
				   type: "POST",
				   url: "<%=request.getContextPath()%>/system/roleAction!updatePage.do",
				   data:{'roleBizBean.id':obj.val()},
				   dataType: "json",
				   async: false,
				   success: function(roleBizBean){
							if(roleBizBean != null){
								
								var optionY = '<option value="Y">停用</option>';
								var optionN = '<option value="N">正常</option>';
								if (roleBizBean.markDelete == 'Y') {
									optionY = '<option value="Y" selected>停用</option>';
								}
								if (roleBizBean.markDelete == 'N') {
									optionN = '<option value="N" selected>正常</option>';
								}
								var body = '<form action="roleAction!updateRole.do" id="roleform" name="roleform" method="post">' +
								'<input type="hidden" id="roleId" value="'+roleBizBean.id+'"/>'+
								'<input type="hidden" id="oldName" value="'+roleBizBean.roleName+'"/>'+
								'<div class="row"><b class="label">角色名称:</b><input id="roleName" value="'+roleBizBean.roleName+'" class="input" />&nbsp;&nbsp;<font color="red" id="message">*</font></div>' +
								'<div class="row"><b class="label">角色状态:</b>'+
								'<select name="status" id="status" style="margin-top: 5px;">' +
								optionN+
								optionY+		
								'</select><font color="red">&nbsp;&nbsp;*</font>' +
								'</div>' +
								'<div class="row"><b class="label">备注:</b><textarea id="roleRemark" rows="3" class="input" style="textmode:multiline;" onkeydown="if (this.value.length>=200){event.returnValue=false}">'+roleBizBean.description+'</textarea></div>' +		
								'</form>';
								var	footer='<div style="text-align:center"><input type="button" value="保存" class="divbtn" id="roleUpdate"/><input type="button" value="取消" class="divbtn" id="rolecancel" /></div>';
								Box("role",450,200,body,"编辑角色",footer);
							}
				   }
				});
		} else if(item == undefined || item <= 0 ) {
			alert("您还没有选择数据!");
			return false;
		} else {
			alert("您只能选择一条数据!");
			return false;
		}
	});
	
	$("#roleUpdate").live("click", function(){
		if("" == $("#roleName").val()){
			$("#message").html("角色名称不能为空！");
			return false;
		} else if($("#roleName").val() == $("#oldName").val()){
			$("#message").html("新、旧角色名称相同！");
			return false;
		} else {
			$("#message").html("*");
		}
		$.ajax({
			   type: "POST",
			   url: "<%=request.getContextPath()%>/system/roleAction!update.do",
			   data:{'roleBizBean.id':$("#roleId").val(),
				     'roleBizBean.roleName':$("#roleName").val(),
				     'roleBizBean.description':$("#roleRemark").val(),
				     'roleBizBean.markDelete':$("#status").val()
				    },
			   dataType: "json",
			   async: false,
			   success: function(msg){
						if(msg.msg !=''){
							$("#message").html(msg.msg);
						} else {
							alert("角色更新成功！");
							$("#form1").attr("action", $("#returnURL").val());
							$("#form1").submit();   
						}
			   }
			});
	});
	
	$("#roleUser").click(function(){
		lockPage();
		var obj = $("input[type=checkbox]:checked.classCheckbox");
		var item = obj.length;
		if(item != undefined &&  item > 0 && item == 1) {
			$("#roleid").val(obj.val());
			if($("#delete_"+$("#roleid").val()).val() == "Y"){
				alert("您选择的角色已经停用了！");
				unlockPage();
				return false;
			}
			$("#form1").attr("action","system/roleAction!getRoleUsers.do");
			$("#form1").submit();
		} else if(item == undefined || item <= 0 ) {
			alert("您还没有选择数据!");
			unlockPage();
			return false;
		} else {
			alert("您只能选择一条数据!");
			unlockPage();
			return false;
		}
	});
	
	$("#roleAuth").click(function(){
		lockPage();
		var obj = $("input[type=checkbox]:checked.classCheckbox");
		var item = obj.length;
		if(item != undefined &&  item > 0 && item == 1) {
			$("#roleid").val(obj.val());
			if($("#delete_"+$("#roleid").val()).val() == "Y"){
				alert("您选择的角色已经停用了！");
				unlockPage();
				return false;
			}
			$("#form1").attr("action","system/roleAction!getRoleAuth.do");
			$("#form1").submit();
		} else if(item == undefined || item <= 0 ) {
			alert("您还没有选择数据!");
			unlockPage();
			return false;
		} else {
			alert("您只能选择一条数据!");
			unlockPage();
			return false;
		}
		unlockPage();
	});

	$("#roleResourse").click(function(){
		lockPage();
		var obj = $("input[type=checkbox]:checked.classCheckbox");
		var item = obj.length;
		if(item != undefined &&  item > 0 && item == 1) {
			$("#roleid").val(obj.val());
			if($("#delete_"+$("#roleid").val()).val() == "Y"){
				alert("您选择的角色已经停用了！");
				unlockPage();
				return false;
			}
			$("#form1").attr("action","system/roleAction!getRoleResourseList.do");
			$("#form1").submit();
		} else if(item == undefined || item <= 0 ) {
			alert("您还没有选择数据!");
			unlockPage();
			return false;
		} else {
			alert("您只能选择一条数据!");
			unlockPage();
			return false;
		}
		unlockPage();
	});
	
});
</script>
</html>